package com.ruoyi.pay.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 */
@ConfigurationProperties(prefix = "ruoyi.pay")
@Validated
@Data
public class PayProperties {

    private Boolean enabled = false;

    /**
     * 微信配置类
     */
    private List<WxPayProperties> wx;
    /**
     * 支付宝配置类
     */
    private List<AliPayProperties> ali;

    public static Map<String, AliPayProperties> aliMap;

    public static Map<String, WxPayProperties> wxMap;

    @PostConstruct
    public void init() {
        if (Objects.nonNull(wx)) {
            wxMap = wx.stream().collect(Collectors.toMap(WxPayProperties::getWxAppId, v -> v));
        }
        if (Objects.nonNull(ali)) {
            aliMap = ali.stream().collect(Collectors.toMap(AliPayProperties::getAliAppId, v -> v));
        }
    }

    public WxPayProperties getByWxAppId(String appId) {
        return wxMap.get(appId);
    }

    public AliPayProperties getByAliAppId(String appId) {
        return aliMap.get(appId);
    }


}
